<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%-- <!-- 导航栏 -->
 <ul class="breadcrumb">
   <li class="active"><a href="/index">首页</a> </li>
<!--    <li><a href="#">项目管理</a></li>
   <li><a href="#">其他</a></li> -->
  <li class="dropdown pull-right"><a class="dropdown-toggle" data-toggle="dropdown" href="#">${username}</a><span class="caret"></span>
	<ul class="dropdown-menu">
		<li><a data-toggle="modal" data-target="#modifyPassword" href="javascript:void(0);">更改密码</a></li>
		<li><a href="#">操作2</a></li>
		<li><a href="#">操作3</a></li>
		<li class="divider">&nbsp;</li>
		<li ><a href="/logOut" >退出</a></li>
	</ul>
  </li>
 </ul> --%>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
	<div class="container-fluid">
		<div class="navbar-header" >
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#sidebar-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="<%=path %>/index"><span>API</span>Creator</a>
			<div style="position: relative;margin-left: 192px;">
			<ul class="nav navbar-nav" id="myNav">
				<c:if test="${user!=null }">
					<li src="<%=path %>/project"><a href="javascript:void(0)"><span
					class="glyphicon glyphicon-list-alt"></span>项目管理</a></li>
					<li src="<%=path %>/document"><a href="javascript:void(0)"><span
					class="glyphicon glyphicon-book"></span>文档管理</a></li>
					 <li src="192.168.10.10:8181/api/api.html"><a href="javascript:void(0)"><span
                    class="glyphicon glyphicon-book"></span>使用说明</a></li> 
				<c:if test="${user.role==1}">
					<li src="<%=path %>/user"><a href="javascript:void(0)"><span
					class="glyphicon glyphicon-user"></span>人员管理</a></li>
					
				</c:if>
				</c:if>
			</ul>
			</div>
			<ul class="user-menu">
							<c:if test="${user!=null }">
					<li class="dropdown pull-right"><a href="#"
						class="dropdown-toggle" data-toggle="dropdown"><span
							class="glyphicon glyphicon-user"></span>${username}<span
							class="caret"></span></a>
						<ul class="dropdown-menu" role="menu">
							<li><a data-toggle="modal" data-target="#modifyPassword"
								href="javascript:void(0);"><span
									class="glyphicon glyphicon glyphicon-edit"></span>&nbsp;<span>修改密码</span></a></li>
							<li><a href="<%=path %>/logOut"><span
									class="glyphicon glyphicon-log-out"></span>&nbsp;<span>退出</span></a></li>
						</ul></li>
				</c:if>
			</ul>
		</div>
	</div>
	<!-- /.container-fluid -->
</nav>

<script>
 
$(function(){
	$(document).on("click","#check_1",function(){
		checkpassword();
	});
})
 function checkpassword() {
	 var oldPassword = $("#oldPassword").val();
	 var newPassword1 = $("#newPassword1").val();
	 var newPassword2 = $("#newPassword2").val();
      var id = ${user.id};
	  $.ajax({
	         type:'POST',
	         url:ctx+'/user/checkPassword',
          data: {oldPassword:oldPassword,newPassword1:newPassword1,newPassword2:newPassword2,id:id},
	         success:function(data){
	        	 
	        	 if(data.code==100){
	        	
	        		$("#oPassword").html( "原密码错误！");
	        		var oldPassword = $("#oldPassword").val("");
	        		return;
	        	 }
	        	 else{
	        		 $("#oPassword").html( "");
	        		 
	        	 }
	        	  if(data.code==500) {
	        		 
			        	 $("#nPassword2").html("两次密码不一致！");
	        	
			         	 var newPassword2 = $("#newPassword2").val("");
			         	
				         return;
			        	
			        } 
			     
	         if(data.code==10) {
	         $("#nPassword2").html("新密码不可以为空！");
	         return;
	         } else{
        		 $("#nPassword2").html( "");
        		 
        		 
        	 }
	         if(data.code==200) {
	        	
	       	 $("#nPassword2").html("成功。请重新登录！");
	       	 	window.location.href = ctx+"/login";
	         }
	         }
	     }) ; 
	}
	
	

 </script>
<!-- 更改密码弹窗-->
<div class="modal fade" id="modifyPassword" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true" position="absolute">
	<div class="modal-dialog" style="width: 500px; height: 600px;">

		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">修改密码</h4>
			</div>

			<div class="modal-body"
				style="overflow-y: auto; width: 497px; height: 300px;">
				<input type="hidden" id="id" name="id" value="${user.id }">
				用户名<input type="text" class="form-control" id="username"
					name="username" value="${user.username}" required="required"
					disabled="disabled"><br> 请输入原密码 <input type="password"
					class="form-control" id="oldPassword" name="oldPassword"
					required="required" onblur="checkpassword()"><span
					id="oPassword"></span><br> <br> 请输入新密码<input
					type="password" class="form-control" id="newPassword1"
					name="newPassword1" required="required"><span
					id="nPassword1"></span><br>
				<br> 再次输入密码<input type="password" class="form-control"
					id="newPassword2" name="newPassword2" required="required"><span
					id="nPassword2"></span><br>
				<br>

			</div>


			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<a id="check_1" class="btn btn-primary" onclick="checkPassword()">
					保存 </a>


			</div>

		</div>
		<!-- /.modal-content -->

	</div>
</div>
<!-- /.modal -->
<!-- end -->
